<template>
  <div class="app-container">
    <div class="item2">
      <div class="header">
        <div class="title1">
          <i class="el-icon-data-analysis"></i><span>立库阈值设置</span>
        </div>
        <div class="backB">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
        </div>
      </div>
    </div>
    <div class="formCenter">
      <el-form
        :model="thresholdqueryParams"
        size="large"
        :inline="true"
        ref="thresholdqueryForm"
        :rules="thresholdformRules"
        label-width="95px"
      >
        <el-form-item label="区域编号:" prop="areaNo">
          <!-- <el-input
            v-model="thresholdqueryParams.areaNo"
            placeholder="请输入区域编号"
            clearable
            @keyup.enter.native="thresholdhandleQuery"
          /> -->
          <el-select v-model="thresholdqueryParams.areaNo" placeholder="请选择" clearable>
            <el-option
              v-for="item in thresholdOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="medium"
            @click="thresholdhandleQuery"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="thresholdtableData"
      border
      height="680"
      v-loading="thresholdloading"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
    >
      <el-table-column align="center" prop="areaNo" label="区域编号">
      </el-table-column>
      <el-table-column align="center" prop="areaType" label="区域类型">
      </el-table-column>
      <el-table-column align="center" prop="remark" label="备注">
      </el-table-column>
      <el-table-column align="center" prop="maxCount" label="最大容器数">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.maxCount"
            placeholder="请输入最大容器数"
          ></el-input>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleMNcontainers(scope.row)"
            >修改最大容器数</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="thresholdqueryParams.pageNum"
        :limit.sync="thresholdqueryParams.pageSize"
        @pagination="thresholdhandleQuery"
      />
    </div>
    <div class="footer">
      <el-dialog
        title="操作验证"
        :visible.sync="centerDialogVisible"
        width="22%"
        left
        :close-on-click-modal="false"
      >
        <el-form
          :model="passForm"
          status-icon
          :rules="passrules"
          ref="passForm"
          label-width="60px"
          class="demo-ruleForm"
        >
          <el-form-item label="密码" prop="pass">
            <el-input
              type="password"
              v-model="passForm.pass"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit('passForm')"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { getcheckPassword,getareaList } from "@/api/subSystem/continer";
import { getthresholdAreaNo, getUpdateMaxCount } from "@/api/multiPass";
export default {
  data() {
    var passwordError = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
      } else {
        getcheckPassword(value).then((res) => {
          this.priorityNum = res.msg;
          if (res.msg == "admin") {
            callback();
          } else if (res.msg == "supper") {
            callback();
          } else if (res.msg == "false") {
            callback(new Error("密码错误"));
          }
        });
      }
    };
    return {
      thresholdOptions: [
        {
          value: "JXB40101",
          label: "JXB40101",
        },
        {
          value: "JXB40102",
          label: "JXB40102",
        },
        {
          value: "JXB40201",
          label: "JXB40201",
        },
        {
          value: "JXB40202",
          label: "JXB40202",
        },
        {
          value: "CK201",
          label: "CK201",
        },
        {
          value: "CK401",
          label: "CK401",
        },
        {
          value: "CK402",
          label: "CK402",
        },
        {
          value: "CK501",
          label: "CK501",
        },
      ],
      // 阀值
      // 区域编号
      total:0,
      thresholdareaNo: null,
      thresholdmaxCount: null,
      thresholdtableData: [],
      thresholdloading: false,
      thresholdqueryParams: {
        pageNum: 1,
        pageSize: 10,
        areaNo: null,
      },
      thresholdformRules: {
        areaNo: [
          { required: false, message: "请输入区域编号", trigger: "blur" },
        ],
      },
      // 密码验证
      centerDialogVisible: false,
      passForm: {
        pass: null,
      },
      passrules: {
        pass: [{ validator: passwordError, trigger: "blur" }],
      },
    };
  },
  mounted(){
    this.thresholdhandleQuery();

  },
  methods: {
    goBack() {
      this.$router.push("/subSystem1");
    },
    //立库阀值查询
    thresholdhandleQuery() {
      // getthresholdAreaNo(this.thresholdqueryParams).then((res) => {
      //   console.log(res);
      //   this.thresholdtableData = [res.data];
      // });
      this.thresholdloading=true;
      getareaList(this.thresholdqueryParams).then((res) => {
        console.log(res);
        this.thresholdtableData = res.rows;
        this.total=res.total;
        this.thresholdloading=false;
      });
    },
    //修改最大容器数
    handleMNcontainers(row) {
      this.thresholdareaNo = row.areaNo;
      this.thresholdmaxCount = parseInt(row.maxCount, 10);
      // console.log(111,this.thresholdareaNo,this.thresholdmaxCount);
      this.centerDialogVisible = true;
      this.passForm.pass = null;
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          getUpdateMaxCount({
            areaNo: this.thresholdareaNo,
            maxCount: this.thresholdmaxCount,
          }).then((res) => {
            console.log(res);
            this.thresholdhandleQuery();
          });
          this.centerDialogVisible = false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  .el-icon-data-analysis::before {
    color: #00d9ff;
    margin-right: 8px;
  }
  .title1 {
    font-size: 16px;
    // margin-bottom: 15px;
    color: #808080;
    width: 170px;
    padding: 5px;
    border-bottom: 1px dotted #8ddfff;
  }
  .header {
    margin-top: -10px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-date-editor.el-input,
    .el-date-editor.el-input__inner {
      width: 220px;
      margin-right: 20px;
    }

    .backB {
      cursor: pointer;

      img {
        width: 20%;
      }
    }
  }
  .formCenter {
    height: 62px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
  }
  .footer {
    margin-top: 20px;
    width: 100%;
    min-height: 200px;
  }
}
</style>